package com.uniandes.edu.co.interfaz.persona;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;

import com.uniandes.edu.co.dto.Tsp;
import com.uniandes.edu.co.excepciones.ExcepcionExiste;
import com.uniandes.edu.co.excepciones.ExcepcionVacio;
import com.uniandes.edu.co.interfaz.mundo.Principal;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AgregarPersona extends javax.swing.JDialog {
	private JLabel jLabel1;
	private Principal principal;
	private JButton jButton1;
	private JTextField jTextField3;
	private JTextField jTextField2;
	private JTextField jTextField1;
	private JLabel jLabel4;
	private JLabel jLabel3;
	private JLabel jLabel2;
	private JButton jButton2;

	/**
	* Auto-generated main method to display this JDialog
	*/
	/*public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				AgregarPersona inst = new AgregarPersona(frame);
				inst.setVisible(true);
			}
		});
	}*/
	
	public AgregarPersona(Principal id) {
		super(id, true);
        principal = id;
        setTitle( "Agregar Persona" );
        initGUI();
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				{
					jLabel1 = new JLabel();
					getContentPane().add(jLabel1);
					jLabel1.setText("Agregar Persona");
					jLabel1.setBounds(46, 12, 346, 26);
					jLabel1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
					jLabel1.setFont(new java.awt.Font("Tahoma",1,14));
					jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
	                jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
				}
				{
					jButton1 = new JButton();
					getContentPane().add(jButton1);
					jButton1.setText("Agregar");
					jButton1.setBounds(46, 180, 129, 23);
					jButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							try {
								Tsp.getSingleton().agregarPersona(jTextField1.getText(), jTextField2.getText(), jTextField3.getText(), Tsp.getSingleton().getPersonas());
								JOptionPane.showMessageDialog(null, "Se ha agregado la persona correctamente");
								dispose();
							} catch (ExcepcionVacio e) {
								// TODO Auto-generated catch block
								JOptionPane.showMessageDialog(null, e.getMessage());
							} catch (ExcepcionExiste e) {
								// TODO Auto-generated catch block
								JOptionPane.showMessageDialog(null, e.getMessage());
							}
						}
					});
				}
				{
					jButton2 = new JButton();
					getContentPane().add(jButton2);
					jButton2.setText("Cancelar");
					jButton2.setBounds(208, 180, 184, 23);
					jButton2.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							dispose();
						}
					});
				}
				{
					jLabel2 = new JLabel();
					getContentPane().add(jLabel2);
					jLabel2.setText("Id de la Persona");
					jLabel2.setBounds(46, 50, 129, 16);
				}
				{
					jLabel3 = new JLabel();
					getContentPane().add(jLabel3);
					jLabel3.setText("Nombre de la Persona");
					jLabel3.setBounds(46, 96, 129, 16);
				}
				{
					jLabel4 = new JLabel();
					getContentPane().add(jLabel4);
					jLabel4.setText("Rol de la Persona");
					jLabel4.setBounds(46, 134, 129, 16);
				}
				{
					jTextField1 = new JTextField();
					getContentPane().add(jTextField1);
					jTextField1.setBounds(208, 47, 184, 23);
				}
				{
					jTextField2 = new JTextField();
					getContentPane().add(jTextField2);
					jTextField2.setBounds(208, 93, 184, 23);
				}
				{
					jTextField3 = new JTextField();
					getContentPane().add(jTextField3);
					jTextField3.setBounds(208, 134, 184, 23);
				}
			}
			this.setSize(441, 260);
			this.setLocationRelativeTo(null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
